const app = getApp();

var util = require('../../utils/common.js'); //引入公共JS


var mid = '';
import { Ycwenda } from 'ycwenda.model.js';
var ycwenda = new Ycwenda();
Page({
  data: {
    showIcon: true,
    //显示返回键以及首页
    noLogin: false,
    //未登录
    lineLogin: true //已登录

  },
  onLoad: function (options) {
    var aid = options.aid;
    var title = options.title;
    this.data.aid = aid;

    this._loadDate();

    this.setData({
      _id: aid,
      title: title
    }); //页面打开判断是否登陆过

    util.isLogin(this);
  },
  _loadDate: function () {
    ycwenda.getAnswers(this.data.aid, data => {
      console.log(data); //该演出问答内容

      this.setData({
        'listrow': data
      });
    }); //获取mid接口

    ycwenda.getMid(res => {
      console.log(res);
      mid = res[0]['mid'];
    });
  },
  formSubmit: function (e) {
    if (e.detail.value.name.length == 0) {
      tt.showToast({
        title: '内容不得为空!',
        icon: 'loading',
        duration: 1000
      });
    } else {
      var name = e.detail.value.name;
      var aid = e.detail.value.aid;
      this.data.name = name;
      this.data.aid = aid;
      this.data.mid = mid;
      ycwenda.getAnswersAdd(this.data.name, this.data.aid, this.data.mid, data => {
        //查询出演出订单数据
        console.log(data);

        if (data == '-1') {
          tt.showToast({
            title: '半小时提交一次',
            icon: 'loading',
            duration: 1500
          });
        } else if (data == '1') {
          tt.showToast({
            title: '提交成功',
            icon: 'loading',
            duration: 1500
          });
        } else {
          tt.showToast({
            title: '数据有误,提交失败',
            icon: 'loading',
            duration: 1500
          });
        }
      });
    }
  },
  //小程序未登录时点击授权登录
  bindGetUserInfo: function () {
    util.noLogin(this);
  }
});